﻿using UnityEditor;
using UnityEngine.UI;

[CustomEditor(typeof(CButton))]
public class CButtonEditor : Editor
{
    CButton button;
    SerializedProperty text, triggerInterval, globalSound;
    SerializedProperty transition;
    SerializedProperty transTarget;
    SerializedProperty pressScale, pressColor, pressSprite, pressTexture;
    SerializedProperty useNativeSize;

    void OnEnable()
    {
        button = (CButton)target;

        if (!button.text) button.text = button.GetComponentInChildren<Text>();

        text = serializedObject.FindProperty("text");
        triggerInterval = serializedObject.FindProperty("triggerInterval");
        globalSound = serializedObject.FindProperty("globalSound");

        //点击变换效果-Begin
        transition = serializedObject.FindProperty("transition");
        transTarget = serializedObject.FindProperty("transTarget");
        pressScale = serializedObject.FindProperty("pressScale");
        pressColor = serializedObject.FindProperty("pressColor");
        pressSprite = serializedObject.FindProperty("pressSprite");
        pressTexture = serializedObject.FindProperty("pressTexture");
        useNativeSize = serializedObject.FindProperty("useNativeSize");
        //点击变换效果-End
    }

    public override void OnInspectorGUI()
    {
        EditorGUILayout.Space();

        EditorGUILayout.PropertyField(text);

        EditorGUILayout.Space();

        EditorGUILayout.PropertyField(triggerInterval);

        EditorGUILayout.Space();

        EditorGUILayout.PropertyField(globalSound);

        //点击变换效果-Begin
        EditorGUILayout.Space();
        EditorGUILayout.PropertyField(transition);
        if (transition.enumValueIndex > 0)
        {
            EditorGUILayout.PropertyField(transTarget);
            if (transition.enumValueIndex == (int)CButton.Transition.Scale)
            {
                EditorGUILayout.PropertyField(pressScale);
            }
            else if (transition.enumValueIndex == (int)CButton.Transition.Color)
            {
                EditorGUILayout.PropertyField(pressColor);
            }
            else if (transition.enumValueIndex == (int)CButton.Transition.Sprite)
            {
                EditorGUILayout.PropertyField(pressSprite);
                EditorGUILayout.PropertyField(useNativeSize);
            }
            else
            {
                EditorGUILayout.PropertyField(pressTexture);
                EditorGUILayout.PropertyField(useNativeSize);
            }
        }
        //点击变换效果-End

        serializedObject.ApplyModifiedProperties();
    }
}